﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Swan.SwanWakeUp
{
    /// <summary>
    /// Interaction logic for AnalogClock.xaml
    /// </summary>
    public partial class AnalogClock : UserControl
    {
        private bool alarmSet;

        public AnalogClock()
        {
            InitializeComponent();
        }

        public DateTime AlarmTime
        {
            get { return this.alarmClock.StartTime; }
            set { this.alarmClock.StartTime = value; }
        }

        public bool AlarmSet 
        {
            get
            {
                return this.alarmClock.AlarmSet;
            }
            set
            {
                 this.alarmClock.AlarmSet = value;
            }
        }

    }


    #region Converters
    [ValueConversion(typeof(DateTime), typeof(int))]
    public class SecondsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime date = (DateTime)value;
            return date.Second * 6;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    [ValueConversion(typeof(DateTime), typeof(int))]
    public class MinutesConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime date = (DateTime)value;
            return date.Minute * 6;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    [ValueConversion(typeof(DateTime), typeof(int))]
    public class HoursConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime date = (DateTime)value;
            return (date.Hour * 30) + (date.Minute / 2);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    [ValueConversion(typeof(DateTime), typeof(string))]
    public class WeekdayConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime date = (DateTime)value;
            return date.DayOfWeek.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }



    [ValueConversion(typeof(bool), typeof(string))]
    public class AlarmSetConverter : IValueConverter
    {
        private string alarmOnString = "Alarm on";
        private string alarmOffString = "Alarm off";

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var set = (bool)value;
            return set ? alarmOnString : alarmOffString;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var set = (string)value;
            return set.Equals(alarmOnString);
        }
    }

    [ValueConversion(typeof(DateTime), typeof(int))]
    public class AlarmDateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var dt = (DateTime)value;
            return (dt.Hour * 30) + (dt.Minute / 2);

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var angle = (int)value;
            var reminder = angle % 30;
            var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, angle / 30, reminder / 2, 0);
            return dt;
        }
    }

    [ValueConversion(typeof(bool), typeof(Color))]
    public class ColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return new SolidColorBrush(((bool)value == true) ? Colors.Green : Colors.Red);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    #endregion
}
